#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
string out[20];
string S[20],s[20];
int pos,op,cnt;
vector<int> A;
long long ans=1;
const long long mod=1000000000000000000;
long long x,y;
void init(){
	S[1]=".................................................................................";
	S[2]=".................................................................................";
	S[3]=".0000000.......1.2222222.3333333.4.....4.5555555.6666666.7777777.8888888.9999999.";
	S[4]=".0.....0.......1.......2.......3.4.....4.5.......6.............7.8.....8.9.....9.";
	S[5]=".0.....0.......1.......2.......3.4.....4.5.......6.............7.8.....8.9.....9.";
	S[6]=".0.....0.......1.2222222.3333333.4444444.5555555.6666666.......7.8888888.9999999.";
	S[7]=".0.....0.......1.2.............3.......4.......5.6.....6.......7.8.....8.......9.";
	S[8]=".0.....0.......1.2.............3.......4.......5.6.....6.......7.8.....8.......9.";
	S[9]=".0000000.......1.2222222.3333333.......4.5555555.6666666.......7.8888888.9999999.";
	S[10]=".................................................................................";
	s[1]="..............................................................................................";
	s[2]=".00000.....1.22222.33333.4...4.55555.66666.77777.88888.99999..................................";
	s[3]=".0...0.....1.....2.....3.4...4.5.....6.........7.8...8.9...9..........IIIIIII.N.....N.FFFFFFF.";
	s[4]=".0...0.....1.22222.33333.44444.55555.66666.....7.88888.99999.............I....NN....N.F.......";
	s[5]=".0...0.....1.2.........3.....4.....5.6...6.....7.8...8.....9..=======....I....N.N...N.F.......";
	s[6]=".00000.....1.22222.33333.....4.55555.66666.....7.88888.99999.............I....N..N..N.FFFFFFF.";
	s[7]="..............................................................=======....I....N...N.N.F.......";
	s[8]=".........................................................................I....N....NN.F.......";
	s[9]="......................................................................IIIIIII.N.....N.F.......";
	s[10]="..............................................................................................";
}
void add(int x,int k){
	if(k==1) for(int i=1;i<=10;i++) out[i]+=S[i].substr(x*8,8);
	else for(int i=1;i<=10;i++) out[i]+=s[i].substr(x*6,6);
}
void solve(){
	if(op==1) for(int i=1;i<=10;i++) out[i]+=s[i].substr(69,24);		
	else for(int i=A.size()-1;i>=0;i--) add(A[i],1);
}
int main(){
    init();
    cin>>cnt;
    while(cnt--){
        string in;
        x=0,y=0,pos=0,op=0,ans=1;
        A.clear();
        for(int i=1;i<=10;i++) out[i].clear();
        cin>>in;
    	while(in[pos]!='^'){
    	    x*=10;
    		x+=(in[pos]-'0');
    		add(in[pos]-'0',1);
    		pos++;
    	} 
    	pos+=2;
    	while(in[pos]!='}'){
    	    y*=10;
    		y+=(in[pos]-'0');
    		add(in[pos]-'0',0);
    		pos++;
    	}
    	for(int i=1;i<=10;i++) out[i]+=s[i].substr(61,8);
    	if(x==1) ans=1;
    	else for(int i=1;i<=y;i++){
    		long long t=ans;
    		long long tt=(ans*x)%mod;
    		if(tt<t||ans*x!=tt){
    			op=1;
    			break;	
    		}
    		ans=tt;
    	}
    	if(op==1){
    	    solve();
    	}else{
    	    while(ans){
    		    A.push_back(ans%10);
    		    ans/=10;
    	    }
    	    solve();
    	}
    	for(int i=1;i<=10;i++) cout<<out[i]<<"."<<endl;
    	printf("\n");
    }
	return 0;
}
